package com.pubinfo.passbook.common.model.drool.job;

import lombok.extern.slf4j.Slf4j;
import org.kie.api.KieServices;
import org.kie.api.event.rule.DebugAgendaEventListener;
import org.kie.api.event.rule.DebugRuleRuntimeEventListener;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import java.util.ArrayList;

@Slf4j
public class DroolsTest {
  
  public static final void main(String[] args) {
    KieServices ks = KieServices.Factory.get();
  
    // From the kie services, a container is created from the classpath
    KieContainer kc = ks.getKieClasspathContainer();
  
    KieSession ksession = kc.newKieSession("jobKS");
  
    ksession.addEventListener(new DebugAgendaEventListener());
    ksession.addEventListener(new DebugRuleRuntimeEventListener());
    
    InputJobVO jobVO = new InputJobVO();
    jobVO.setWorkingAge(20);
    ksession.insert(jobVO);
    
    // and fire the rules
    int total = ksession.fireAllRules();
    ksession.dispose();
    
    log.info("执行了 {} 条规则", total);
    log.info("执行后的名称:{}", jobVO.getTotalAmount());
    log.info("执行后的姓名:{}", jobVO.getWorkingAge());
  }
  
}
